﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Ricciolo.PaperBoy.Feeds;
using System.Windows;

namespace Project_CFT2.ViewModel
{
    internal class FurnitureBlockViewModel : ViewModelBase
    {
        
      //  private myDataItem _dataItem;
      //  private string t;
      //  private string im;
        
        //private static DataClasses1DataContext _dataDC = new DataClasses1DataContext();
        //private ObservableFurnitureItems _FurnitureItems;
        //private static DataClasses1DataContext _dataDC = new DataClasses1DataContext();
        
        private ObservableCollection<myFurnitureDataItem> _furnitureItems;

        public FurnitureBlockViewModel(myFurnitureDataItem item)
        {
        //    _dataItem = item;
         //   t = item.Title;
         //   im = item.Im;
            _furnitureItems.Add(item);
//            _furnitureItems = new ObservableFurnitureItems(_dataDC);
            // _FurnitureItems = new ObservableFurnitureItems(_dataDC);

        }

        //public FolderViewModel(Furniture i)
        //{

        //    _FurnitureItems = new ObservableFurnitureItems(_dataDC);
        //}

        protected override string GetTitle() { return "X"; }

        private ReadOnlyCollection<ViewModelBase> _items;

        public ReadOnlyCollection<ViewModelBase> Items
        {
            get
            {
                if (_items == null)
                {
                    var bw = new BackgroundWorker();
                    bw.DoWork += RefreshItems;
                    bw.RunWorkerAsync();
                }
                
                return _items;
            }
        }
        /* public ObservableFurnitureItems Items
         {
             get
             {


                 return _furnitureItems;
             }
         }*/

        void RefreshItems(object sender, DoWorkEventArgs e)
        {
            //_folder.FoldersAndFeeds.Refresh();
            LoadItems();
        }

        private void LoadItems()
        {
            var itemsList = new List<ViewModelBase>();


            foreach (var item1 in _furnitureItems)
            {



                //foldersAndFeedsList.Add(new FurnitureViewModel(new myDataItem(item1.Name.ToString(), item1.Price.ToString(), item1.Type.ToString(), item1.Price.ToString(), item1.Image.ToString())));
                itemsList.Add(new FurnitureViewModel(item1 ));
                //MessageBox.Show("Hello");
            }
            /*
            foreach (var feedBase in _folder.FoldersAndFeeds)
            {
                if (feedBase is FeedFolder)
                {
                    var subFolder = feedBase as FeedFolder;
                    if (subFolder.TotalItemCount > 0)
                        foldersAndFeedsList.Add(new FolderViewModel(subFolder));
                }
                else if (feedBase is Feed)
                {
                    var feed = feedBase as Feed;
                    if (feed.ItemCount > 0)
                        foldersAndFeedsList.Add(new FurnitureViewModel(feed));
                }
            }*/

            _items = new ReadOnlyCollection<ViewModelBase>(itemsList);
            RaisePropertyChanged("Items");
        }
    }
}